//品牌控制层
app.controller('baseController', function ($scope) {

    //重新加载列表 数据
    $scope.reloadList = function () {
        //切换页码
        $scope.search($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
    }

    //分页控件配置
    $scope.paginationConf = {
        currentPage: 1,
        totalItems: 10,
        itemsPerPage: 10,
        perPageOptions: [10, 20, 30, 40, 50],
        onChange: function () {
            $scope.reloadList();//重新加载
        }
    };

    $scope.selectIds = [];//选中的ID集合

    //更新复选
    $scope.updateSelection = function ($event, id) {
        if ($event.target.checked) {//如果是被选中,则增加到数组
            $scope.selectIds.push(id);
        } else {
            var idx = $scope.selectIds.indexOf(id);
            $scope.selectIds.splice(idx, 1);//删除 
        }
    }
    $scope.removeFromArray = function (array,element) {
        var idx = array.indexOf(element);
        if(idx <0){
            return false;
        }
        array.splice(idx,1);
        return true;
    }
    $scope.extractStringFromArrayString = function (arrayString,extractKey) {
        var array = JSON.parse(arrayString)
        var keyArray = $scope.extractFromArray(array,extractKey);
        return keyArray.toString();
    }
    $scope.extractFromArray = function (array,extractKey) {
        var keys = [];
        array.forEach(function (item) {
            keys.push(item[extractKey]);
        });
        return keys;
    }

});